s = "Hello,Python world!"
#1
print(len(s))
#2
print(s.count("o"))
#3
print(s.upper())
#4
print(s.lower())
#5
print(s.find("Python"))
#6
print(s.replace("world", "universe"))
#7
print(s.startswith("Hello"))
#8
print(s.endswith("!"))
#9
print(s.split(","))
#10
print(s.strip("!"))
#11
print(s[::-1])
#12
print(s[6:12])
#13
print(s.replace("Hello, ", ""))
#14
print("Hello," + " " + "World!")
#15

#16
print(s.find('a'))
#17
print(s.rfind('e'))
#18
print(s.count(" "))
#19
for char in s:
    print(char)
#20
print(list(s))
#21
sorted_list = sorted(list(s))
#22
print(s.isdigit())
#23
print(' '.join(['Hello,', 'Python', 'World!']))
#24
print("Number: %d" % 100)
#25
print(s.islower())
#26
s.isupper()
#27
'-'.join([str(x) for x in [1, 2, 3]])
#28
position = []
for i , char in enumerate(s):
    if char == 'o':
        position.append(i)
print(position)
#29
print(s.replace('o', 'O', 1))
#30
print(s[:6] + "amazing " + s[6:])
#进阶
s = "Python is great!"
#1
reversed_str = ""
for char in s:
    reversed_str = char + reversed_str
print(reversed_str)
#2
count = 0
for char in s:
    if char == 't':
        count += 1
print(count)
#3
new_s = ""
for char in s:
    if char == " ":
        new_s += "_"
    else:
        new_s += char
print(new_s)
#4
s2 = "A man, a plan, a canal, Panama!"
clean_str = ""
for char in s2:
    if char.isalnum():
        clean_str += char.lower()
is_palindrome = clean_str == clean_str[::-1]
print(is_palindrome)
#5
target = "is"
index = -1
for i in range(len(s) - len(target) + 1):
    if s[i:i+len(target)] == target:
        index = i
        break
print(index)
#6
new_str = ""
inserted = False
for char in s:
    new_str += char
    if char == 't' and not inserted:
        new_str += "_inserted"
        inserted = True
print(new_str)
#7
target = "great"
replacement = "awesome"
new_str = ""
i = 0
while i < len(s):
    if s[i:i+len(target)] == target:
        new_str += replacement
        i += len(target)
        break
    else:
        new_str += s[i]
        i += 1
new_str += s[i:]
print(new_str)
#8
mid = len(s) // 2
first_half = s[:mid]
second_half = s[mid:]
reversed_order = second_half + first_half
print(reversed_order)
#9
words = s.split()
capitalized_list = [word[0].upper() for word in words]
print(capitalized_list)
#10
s3 = "encryption"
mapping = {
    'a': 'm', 'b': 'n', 'c': 'o', 'd': 'p', 'e': 'q', 'f': 'r', 'g': 's',
    'h': 't', 'i': 'u', 'j': 'v', 'k': 'w', 'l': 'x', 'm': 'y', 'n': 'z',
    'o': 'a', 'p': 'b', 'q': 'c', 'r': 'd', 's': 'e', 't': 'f', 'u': 'g',
    'v': 'h', 'w': 'i', 'x': 'j', 'y': 'k', 'z': 'l'
}
encrypted = ""
for char in s3:
    encrypted += mapping.get(char, char)
print(encrypted)


